package com.example.simplesvc;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

public class MyServerStopListenerRegister {

    private static MyServerStopListenerRegister INST  = new MyServerStopListenerRegister();


    Logger log = LoggerFactory.getLogger(MyServerStopListenerRegister.class);
    private List<MyServerStopListener> listenerList = new ArrayList<>();
    public static MyServerStopListenerRegister getInstance() {
        return INST;
    }


    public void registerListener(MyServerStopListener listener) {
        if(!listenerList.contains(listener)) {
            listenerList.add(listener);
        }
    }

    public void notifyAllListenersServerStopping() {
        log.info("trying to notify listensers server stopping");
        listenerList.stream()
                .forEach(listener -> {
                    log.info(" notify listenser{} server stopping",listener);
                    listener.onServerStopping();
                });

    }
}
